import requests

from api.ihrm_login_api import IhrmLoginApi


class IhrmEmpApi(object):
    # 定义 添加员工方法
    @classmethod
    def add_emp(cls, header, req_data):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/user",
                             headers=header, json=req_data)
        return resp

    # 定义 查询员工 方法
    @classmethod
    def query_emp(cls, emp_id, header):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                            headers=header)
        return resp

    # 定义 修改员工 方法
    @classmethod
    def modify_emp(cls, emp_id, header, req_data):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                            headers=header, json=req_data)
        return resp

    # 定义 删除员工 方法
    @classmethod
    def delete_emp(cls, emp_id, header):
        resp = requests.delete(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                               headers=header)
        return resp


if __name__ == '__main__':
    data = {"mobile": "13800000002", "password": "123456"}
    resp0 = IhrmLoginApi.login(data)

    req_header = {"Authorization": resp0.json().get("data")}
    json = {"username": "三天三夜", "mobile": "13134781203", "workNumber": "9527"}
    emp_id = "1495220060174802944"
    resp = IhrmEmpApi.add_emp(req_header,json)
    print("添加员工结果: ",resp.json())
    # resp = IhrmEmpApi.query_emp(emp_id, req_header)
    # print("查询员工结果: ", resp.json())
    # modify_data = {"username": "七天七夜","password":"123456"}
    # resp = IhrmEmpApi.modify_emp(emp_id, req_header, modify_data)
    # print("修改员工结果: ", resp.json())
    # resp = IhrmEmpApi.delete_emp("", req_header)
    # print(resp.json())
